-
-
Notifications
You must be signed in to change notification settings - Fork 205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added three functions for linalg: SVD, Least Squares and PseudoInverse #258
Conversation
…meric!), Least Squares and PseudoInverse
matrix = to_mpmath_matrix(m) | ||
U, S, V = mp.svd(matrix) | ||
S = mp.diag(S) | ||
print(U, S, V) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't forget to remove this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, thanks!
Sympy implements the singular value decomposition for exact inputs, see here. We should probably us this version if the argument is exact and the mpmath version otherwise. Edit: Can never get the md hyperlink syntax right. |
Also, we have a helper class function for wrapping Sympy functions. It's called There's also I'm happy to help with this. Let me know if you have any questions. |
Hey, actually the function you're linking is the one I am using. But if you look closely, it's the mpmath Matrix package of sympy and unfortunately not the sympy Matrix... Took me some time to realize, too. So I guess at least sympy doesn't have a algebraic solution up to now. |
Oh, you're right sorry. I see there's an Sympy issue sympy/sympy#6832 to track this missing functionality. The only option we have is to provide the numerical SVD (as you've done). |
</dl> | ||
|
||
>> SingularValueDecomposition[{{1, 2}, {2, 3}, {3, 4}}] | ||
= {{-11 / 6, -1 / 3, 7 / 6}, {4 / 3, 1 / 3, -2 / 3}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is failing (because we get inexact answers). It's nice to have the tests pass, and unfortunately in the current system there's no way to mark a test as xfail. I'd suggest adding a Line before this test explaining why the results are inexact, and then testing the inexact results.
Let me know if that's unclear.
Ideally I'd like to get this one into 0.9 too. |
Opened #321. |
SVD is only numeric and implemented via mpmath. Not sure if that's acceptable or not? Might need a check, too.